package com.bos.service.impl;

import com.bos.dao.repositories.PermsRepository;
import com.bos.domian.system.Permission;
import com.bos.service.PermsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.util.List;

/**
 * @author misterWei
 * @create 2018年12月31号:16点03分
 * @mailbox mynameisweiyan@gmail.com
 */
@Service
@Transactional(rollbackFor = {NullPointerException.class, ParseException.class,NumberFormatException.class})
public class PermsServiceImpl implements PermsService {
    @Autowired
    PermsRepository permsRepository;
    /**
     * 根据当前用户去查询此用户所有的权限认证
     * @param  userId 用户的Id
     * @return  返回所有的权限
     *
     * */
    @Override
    public List<Permission> findByUser(Integer userId) {
        if (userId==1) {
            return permsRepository.findAll();
        }else{
            return permsRepository.byUserPerms(userId);
        }

    }

    @Override
    public List<Permission> findAll() {
        return permsRepository.findAll();
    }

    @Override
    public void save(Permission model) {
        permsRepository.saveAndFlush(model);
    }

}
